VHD: Fix locale aware character encoding handling
authorPhilipp Hahn <hahn@univention.de>
Sun, 8 Mar 2015 10:54:17 +0000 (11:54 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 11 Mar 2015 11:36:39 +0000 (11:36 +0000)
commit816d50cb49a61fab8c96512e22bba9d5256a008c
tree6f4945e3bf9c9270e14cc0cdc9ceee0411cded34
parent0c8d70336bbf3d83d6d927fecdd716010c4907dc
VHD: Fix locale aware character encoding handling

ASCII is 7 bit only, which does not work in UTF-8 environments:
> failed to read parent name

Setup locale in vhd-util to parse LC_CTYPE and use the right codeset
when doing file name encoding and decoding.

Increase allocation for UTF-8 buffer as one UTF-16 character might use
twice as much space in UTF-8 (or more).

Don't check outbytesleft==0 as one UTF-8 characters get encoded into
1..8 bytes, so it's perfectly fine (and expected) for the output to have
remaining bytes left.

Test-case:
$ ./vhd-util create -n ä.vhd -s 1
$ ./vhd-util snapshot -n snap.vhd -p ä.vhd ; echo $?

See
<http://unix.stackexchange.com/questions/48689/effect-of-lang-on-terminal>
for more information about the details of handling the encoding right.

Signed-off-by: Philipp Hahn <hahn@univention.de>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/blktap2/vhd/lib/libvhd.c
tools/blktap2/vhd/vhd-util.c